var copyPut = function() {
    describe('put方法拷贝文件', function () {
        let key = 'demo-copy.txt';
        let sourceBucket = 'wyr123';
        let sourceKey = 'demo.txt';
        let encryptionKey = 'demo-copy.secret.txt';
        let sourceEncryptionKey = 'demo.secret.txt';
        let file = blob({ size: 1024 * 1024 * 5 });
        before('上传文件,并通过请求头设置用户自定义元数据', function (done) {
            this.timeout(10000);
            ks3.putObject({
                key: sourceKey,
                bucket: sourceBucket,
                file,
                headers: {
                    'x-kss-meta-info': 'abc'
                }
            }).then(res => {
                should.not.exist(res.error);
                res.statusCode.should.be.equal(200);
                done()
            })
        })
        after('删除文件', function (done) {
            this.timeout(2000);
            ks3.delObject({
                key: sourceKey,
                bucket: sourceBucket,
            }).then(res => {
                should.not.exist(res.error);
                res.statusCode.should.be.equal(204);
                done()
            })
        })
        describe('拷贝文件,不设置存储类型', function () {
            it('拷贝文件', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的信息和存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.StorageClass.should.be.equal('STANDARD');
                    object.Size.should.be.equal(file.size.toString());
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('拷贝服务端加密的文件', function () {
            it('上传服务端加密的文件', function (done) {
                this.timeout(5000);
                ks3.putObject({
                    key: sourceEncryptionKey,
                    bucket: sourceBucket,
                    file: blob({ size: 1024 * 1024 * 5 }),
                    encryption: true
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('拷贝服务端加密的文件', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key: encryptionKey,
                    sourceBucket,
                    sourceKey: sourceEncryptionKey,
                    encryption: true
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的信息和存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: encryptionKey,
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.Size.should.be.equal(file.size.toString());
                    object.StorageClass.should.be.equal('STANDARD');
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除被拷贝的加密文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                   key: sourceEncryptionKey,
                   bucket: sourceBucket
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
            it('删除加密复制生成的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: encryptionKey
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('拷贝归档类型的文件', function () {
            it('上传归档类型的文件', function (done) {
                this.timeout(10000);
                ks3.putObject({
                    key: 'demo.archive.txt',
                    bucket: sourceBucket,
                    file: blob({ size: 1024 * 1024 * 5 }),
                    headers: {
                        'x-kss-storage-class': 'ARCHIVE'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done()
                })
            })
            it('拷贝文件,结果应该是403', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key: 'demo.archive-copy.txt',
                    sourceBucket,
                    sourceKey: 'demo.archive.txt',
                }).then(res => {
                    console.log('res.statusCode------' ,res, res.statusCode)
                    // should.not.exist(res.data);
                    res.statusCode.should.be.equal(403);
                    done();
                })
            })
            it('删除归档文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: 'demo.archive.txt',
                    bucket: sourceBucket,
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('通过参数设置存储类型为STANDARD_IA', function () {
            it('参数storageClass值为STANDARD_IA', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey,
                    storageClass: 'STANDARD_IA'
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的信息和存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.StorageClass.should.be.equal('STANDARD_IA');
                    object.Size.should.be.equal(file.size.toString());
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                console.log(key)
                this.timeout(2000);
                ks3.delObject({
                    key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('通过请求头设置存储类型为ARCHIVE', function () {
            it('参数未设置存储类型,请求头中的x-kss-storage-class值为ARCHIVE', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey,
                    headers: {
                        'x-kss-storage-class': 'ARCHIVE'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的信息和存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.StorageClass.should.be.equal('ARCHIVE');
                    object.Size.should.be.equal(file.size.toString());
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('通过请求头设置存储类型为STANDARD_IA,覆盖掉参数设置的存储类型', function () {
            it('参数storageClass值为STANDARD,请求头x-kss-storage-class值为STANDARD_IA,参数设置的值应被覆盖', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey,
                    storageClass: 'STANDARD',
                    headers: {
                        'x-kss-storage-class': 'STANDARD_IA'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的信息和存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.StorageClass.should.be.equal('STANDARD_IA');
                    object.Size.should.be.equal(file.size.toString());
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('拷贝源Object的元数据信息', function () {
            it('请求头x-kss-metadata-directive值为COPY', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey,
                    headers: {
                        'x-kss-metadata-directive': 'COPY'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的元信息', function (done) {
                this.timeout(2000);
                ks3.headObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('不拷贝源Object的元数据信息', function () {
            it('请求头x-kss-metadata-directive值为REPLACE', function (done) {
                this.timeout(5000);
                ks3.putObjectCopy({
                    key,
                    sourceBucket,
                    sourceKey,
                    headers: {
                        'x-kss-metadata-directive': 'REPLACE'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取拷贝文件的元信息', function (done) {
                this.timeout(2000);
                ks3.headObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除拷贝的文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key: key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
    })
}